<?php 
$dbhost='127.0.0.1';
$dbuser='root';
$dbpwd ='song@491497047';
$dbName='email';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
$query=$mysqli->query("SELECT tag FROM analyse group by tag ");
$tagName=array();

$query=$mysqli->query("SELECT tag FROM analyse group by tag ");
$tagList=array('all');
while ($list=$query->fetch_assoc()){
    $tagList[]=$list['tag'];
}

 

$thetag='all';
$day=date("Y-m-d", strtotime("-1 day"));
foreach ($tagList as $thetag){

    if ($thetag != 'all'){
        $sql="SELECT count(id) as count FROM analyse where day='".$day."' and  tag='".$thetag."' ";
    }else{
        $sql="SELECT count(id) as count FROM analyse where day='".$day."' ";
    }
    $queryPv=$mysqli->query($sql);
    $pvInfo=$queryPv->fetch_array();

    
    if ($thetag != 'all'){
        $sql="SELECT count(DISTINCT uid) as count FROM analyse where day='".$day."' and  tag='".$thetag."'  ";
    }else{
        $sql="SELECT count(DISTINCT uid) as count FROM analyse where day='".$day."'   ";
    }
    $queryUv=$mysqli->query($sql);
    $uvInfo=$queryUv->fetch_array();
    
    if ($thetag != 'all'){
        $sql="SELECT count(DISTINCT ip) as count FROM analyse where day='".$day."' and  tag='".$thetag."'  ";
    }else{
        $sql="SELECT count(DISTINCT ip) as count FROM analyse where day='".$day."'   ";
    }
    $queryIp=$mysqli->query($sql);
    $ipInfo=$queryIp->fetch_array();
  
    $query=$mysqli->query("SELECT id FROM log_2 where day='".$day."' and tag='".$thetag."'  limit 0,1 ");
    if($query->num_rows>0){
        
    }else{
        $sql="insert into log_2(day,pv,uv,ip,tag) values('".$day."','".$pvInfo['count']."','".$uvInfo['count']."'
,'".$ipInfo['count']."','".$thetag."')";
        $mysqli->query($sql);
    }
    
    
}
echo 'done';
?>
